package com.ceadeal.javafxboot.component;

import com.arcsoft.face.ActiveFileInfo;
import com.arcsoft.face.FaceEngine;
import com.arcsoft.face.enums.ErrorInfo;
import com.ceadeal.javafxboot.config.ArcSoftConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @Author 张寒轩
 * @Date 2021/3/19 9:53
 * @Description 虹软人脸识别初始化
 */
@Component
@Slf4j
public class ArcSoftInit {

    @Resource
    private ArcSoftConfig arcSoftConfig;

    @PostConstruct
    public void initialize() {
        FaceEngine faceEngine = new FaceEngine(arcSoftConfig.getLibPath());
        //激活引擎
        int errorCode = faceEngine.activeOnline(arcSoftConfig.getAppId(), arcSoftConfig.getSdkKey());
        if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
            throw new RuntimeException("虹软人脸识别引擎激活失败...");
        }
        log.info("虹软人脸识别引擎激活成功...");
        ActiveFileInfo activeFileInfo = new ActiveFileInfo();
        errorCode = faceEngine.getActiveFileInfo(activeFileInfo);
        if (errorCode != ErrorInfo.MOK.getValue() && errorCode != ErrorInfo.MERR_ASF_ALREADY_ACTIVATED.getValue()) {
            throw new RuntimeException("虹软人脸识别获取激活文件信息失败...");
        }
        log.info("虹软人脸识别获取激活文件信息成功...");
        faceEngine.unInit();
    }
}